<!--  -->
<template>
  <div class="app-container">
    <el-upload
      class="upload-demo"
      :action="uploadUrl"
      :headers="headers"
      :limit="1"
      accept=".xls"
      :on-success="uploadSuccess"
    >
      <div slot="tip" class="el-upload__tip">只能上传xls文件</div>
      <el-button size="small" type="primary">点击上传</el-button>
      <el-button v-if="showDownload" size="small" type="primary" @click="download">下载</el-button>
    </el-upload>
  </div>
</template>

<script>
import { getToken } from '@/utils/auth'
export default {

  components: {},
  data() {
    return {
      headers: {
        'Authorization': getToken()
      },
      uploadUrl: process.env.VUE_APP_BASE_API + '/excel/sort',
      showDownload: false,
      downloadUrl: ''
    }
  },

  computed: {},

  mounted: {
  },

  methods: {
    uploadSuccess(res) {
      this.showDownload = true
      this.downloadUrl = res.data
    },
    download() {
      window.open(this.downloadUrl)
    }
  }
}

</script>
<style lang='scss' scoped>
</style>
